package jwr;

import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.JPanel;

public class MouseMotionAction extends JPanel implements MouseListener, MouseMotionListener{
	Point p1,p2;
	public MouseMotionAction() {
		addMouseListener(this);
		addMouseMotionListener(this);
	}
	
	@Override
	public void mouseExited(MouseEvent e) {	}
	@Override
	public void mouseMoved(MouseEvent e) {	}

	@Override
	public void mouseClicked(MouseEvent e) {}
	
	@Override
	public void mouseEntered(MouseEvent e) {}

	@Override
	public void mousePressed(MouseEvent e) {	
		p1 = e.getPoint();
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		p2 = e.getPoint();
		repaint();
	}
	
	@Override
	public void mouseDragged(MouseEvent e) {
		p2 = e.getPoint();
		repaint();
	}

	@Override
	protected void paintComponent(Graphics g){
		super.paintComponent(g);
		g.drawLine(p1.x, p1.y, p2.x, p2.y);
	}
	
}
